package com.zuo.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zuo.model.LoginModel;
import com.zuo.service.LoginService;

@Controller("loginController")
@RequestMapping(value = "/")  
public class LoginController {

	@Autowired
	private LoginService service;
	
	@RequestMapping("login.do")
	@ResponseBody
	public LoginModel login(String username, String password,HttpServletRequest req){
		LoginModel lm  = new LoginModel();	
		String msg = service.checkPassword(username, password);

		if( msg == null){
			lm.setUsername(username);
			lm.setSessionId(req.getSession().getId());
			lm.setIp(req.getRemoteAddr());
			System.out.println("通过返回url");
			lm.setUrl("main.do");
			req.getSession().setAttribute("loginModel", lm);
		}else{
			lm.setMsg(msg);
		}
		return lm;
	}
	
	
	@RequestMapping("main.do")
	public String main(){
		return "WEB-INF/ym/main.html";
	}
	
	
}
